<% @page_title = "多背一公斤 | #{@school.title}" %>

<% content_for :head do -%>
  <script type="text/javascript" src="/javascripts/thickbox.js"></script>
  <link rel="stylesheet" href="/stylesheets/thickbox.css" type="text/css" media="screen" />
<% end -%>

<% visited = @school.visited_by(current_user) %>

<% content_for(:sidebar) do %>  
	<h4><%= link_to "上传学校的照片", new_photo_path(:school_id => @school.id) %></h4>
	<% if logged_in? && current_user.is_admin? -%>
    <h4><%= link_to "添加一个学生信息", new_student_url(@school.id) %></h4>
  <% end -%>
  <h4><%= link_to "提交一所学校信息", new_school_path %></h4>
  <h4><%= link_to "返回学校首页", schools_path %></h4>
  
  <% if @school.editable_by? current_user -%>
    <h3 class="nt">管理员操作 <%= title_suffix %></h3>
    <p>- <%= link_to "返回待验证学校列表", unconfirmed_schools_url %><br />
    - <%= link_to "编辑学校信息", edit_school_path(@school) %><br />
    - <%= link_to "删除（放入回收站）", school_path(@school), :confirm => "学校信息会被放入回收站，只有网站管理员才能恢复。确定删除么？", :method => :delete %><br />
    <% unless @school.is_validate %>
      - <%= link_to "通过信息验证", validate_school_path(@school), :method => 'put' %></p>
    <% else %>
      - <%= link_to "取消信息验证", validate_school_path(@school), :method => 'put' %></p>
    <% end %>
  <% end -%>
  
  <% if @school.is_meta? -%>
    <h4><%= link_to "完善学校信息", edit_school_url(@school.id) %></h4>
  <% else -%>
    <% if @school.is_validate %>
      <h4>通过学校管理小组验证</h4>
    <% else %>
      <h4>等待学校管理小组验证</h4>
    <% end %>
    <p class="tip">通过验证之前，学校资料可以由提交者（<%= link_to @school.submitor.login, user_path(@school.submitor.id) %>）和学校管理小组成员编辑；通过验证之后，学校资料只能由学校管理小组编辑</p>
  <% end -%> 
  
  <h3 class="nt">谁去过 <%= title_suffix %></h3>
  <% unless @travelers.blank? -%>
  <%= render :partial => "/shared/users", :object => @travelers %>
  <% else -%>
  <p>还没人去过</p>
  <% end -%>
<% end %>

<h3 class="note"><%= h @school.title %></h3>

<% if @school.is_meta -%>
<div class="dbb">
  <table border="0" cellspacing="5" cellpadding="0" width="100%">
  <tr>
    <td width="20%"><label for="area">学校所在地区：</label></td>
    <td><%= areas_crumble_path_with_link(@school.area){|p| p.title} %></td>
  </tr>
  <tr>
    <td><label for="address">学校地址：</label></td>
    <td><%= h @school.address %></td>
  </tr>
  <tr>
    <td><label for="telephone">学校电话：</label></td>
    <td><%= h @school.telephone %></td>
  </tr>
  <tr>
    <td><label for="master">校长姓名：</label></td>
    <td><%= h @school.master %></td>
  </tr>
  <tr>
    <td><label for="contact_name">学校联系人：</label></td>
    <td><%= h @school.contact_name %></td>
  </tr>
  <tr>
    <td><label for="contact_role">联系人职务：</label></td>
    <td><%= h @school.contact_role %></td>
  </tr>
  <tr>
    <td><label for="contact_telephone">联系人电话：</label></td>
    <td><%= h @school.contact_telephone %></td>
  </tr>
</table>
</div>
<% unless @school.advice_html.blank? -%>
<table border="0" cellspacing="5" cellpadding="0" width="100%">
  <tr>
    <td width="120" valign="top"><label for="advice">受灾情况和物资需求：</label></td>
  </tr>
  <tr>
    <td><%= @school.advice_html %></td>
  </tr>
</table>
<% end -%>

<% else -%>

<div class="span-10 prepend-1">
	<%= avatar_for @school.submitor, "small" %>
	<%= link_to h(@school.submitor.login), user_path(@school.submitor.id) %>
	<span class="tip">提交于
	<%= show_date @school.created_at %></span>
</div>

<div id="join_in" class="span-5 last">
  <% if !logged_in? || visited==:false -%>
    <h4><a href="javascript:void(0)" onclick="$('#visit_date').show()">我去过</a></h4>
  <% else -%>
    <span class="tip">我 <%= visited %> 去过 <a href="javascript:void(0)" onclick="$('#visit_date').show()">修改时间</a></span>
  <% end -%>
  
  <% form_for :visited, :url => visit_school_path(@school.id), :html => {:method => 'put'} do |f| -%>
  <div id="visit_date" style="display:none">
    <span class="tip">什么时间去的？</span><br />
    <%= f.date_select :visit_at, :start_year => 1980, :use_month_names => Status::MONTHS %>
    <%= submit_tag "确定" %>
  </div>
  <% end -%>
</div>
<div class="clear"></div>

<ul id="tabnav" class="school-nav">
	<li id="base-li" class="current"><a href="javascript:show_form('base')" title="学校基本信息">学校基本信息</a></li>
	<li id="traffic-li"><a href="javascript:show_form('traffic')" title="交通指南">交通指南</a></li>
	<li id="require-li"><a href="javascript:show_form('require')" title="学校需求">学校需求</a></li>
	<li id="finder-li"><a href="javascript:show_form('finder')" title="信息收集人">信息收集人</a></li>
</ul>
<div id="base-form">
  <table border="0" cellspacing="5" cellpadding="0">
    <tr>
      <td><label for="area">学校所在地区：</label></td>
      <td><%= areas_crumble_path_with_link(@school.area){|p| p.title} %></td>
    </tr>
    <tr>
      <td><label for="address">学校地址：</label></td>
      <td><%= h @school.address %></td>
    </tr>
    <tr>
      <td><label for="zipcode">邮政编码：</label></td>
      <td><%= h @school.zipcode %></td>
    </tr>
		<% if logged_in? %>
    <tr>
      <td><label for="master">校长姓名：</label></td>
      <td><%= h @school.master %></td>
    </tr>
    <tr>
      <td><label for="telephone">学校电话：</label></td>
      <td><%= h @school.telephone %></td>
    </tr>
    <tr>
      <td><label for="contact_name">学校联系人：</label></td>
      <td><%= h @school.contact_name %></td>
    </tr>
    <tr>
      <td><label for="contact_role">联系人职务：</label></td>
      <td><%= h @school.contact_role %></td>
    </tr>
    <tr>
      <td><label for="contact_telephone">联系人电话：</label></td>
      <td><%= h @school.contact_telephone %></td>
    </tr>
    <tr>
      <td><label for="contact_email">联系人邮件：</label></td>
      <td><%= h @school.contact_email %></td>
    </tr>
		<% else %>
		<tr>
			<td colspan="2" align="center">详细联系人信息请<%= link_to "登录", login_url %>后浏览</td>
		</tr>
		<% end %>
    <tr>
      <td><label for="level_amount">学制：</label></td>
      <td><%= h @school.level_amount %></td>
    </tr>
    <tr>
      <td><label for="teacher_amount">教职工数：</label></td>
      <td><%= h @school.teacher_amount %></td>
    </tr>
    <tr>
      <td><label for="class_amount">班级数：</label></td>
      <td><%= h @school.class_amount %></td>
    </tr>
    <tr>
      <td><label for="student_amount">在校生数：</label></td>
      <td><%= h @school.student_amount %></td>
    </tr>
    <tr>
      <td><label for="has_library">是否有图书室：</label><br />
          <label for="book_amount">现有图书：</label></td>
      <td><%= Status::School::RadioBox::status_for(@school.has_library) %><br />
          <%= h @school.book_amount %> 册</td>
    </tr>
    <tr>
      <td><label for="has_pc">是否有电脑：</label><br />
          <label for="pc_amount">现有电脑：</label><br />
          <label for="has_internet">是否能上网：</label></td>
      <td><%= Status::School::RadioBox::status_for(@school.has_pc) %><br />
          <%= h @school.pc_amount %> 台<br />
          <%= Status::School::RadioBox::status_for(@school.has_internet) %></td>
    </tr>
    <tr>
      <td class="label"><label for="incoming_from">乡村主要收入来源：</label></td>
      <td><%= h @school.incoming_from %><br />
  		    <%= h @incoming_from %></td>
    </tr>
    <tr>
      <td><label for="incoming_average">当地年人均收入：</label></td>
      <td><%= Status::School::INCOMING_AVERAGE[@school.incoming_average.to_i] %></td>
    </tr>
    <tr>
      <td class="label"><label for="has_ngo">是否有公益组织或<br />民间人士资助：</label></td>
      <td><%= Status::School::RadioBox::status_for(@school.has_ngo) %></td>
    </tr>
    <% if @school.has_ngo == Status::School::RadioBox::YES %>
    <tr>
      <td><label for="ngo_name">组织名称：</label></td>
      <td><%= h @school.ngo_name %></td>
    </tr>
    <tr>
      <td><label for="ngo_start_at">开展时间：</label></td>
      <td><%= h @school.ngo_start_at %></td>
    </tr>
    <tr>
      <td><label for="ngo_contact_name">联系人：</label></td>
      <td><%= h @school.ngo_contact_name %></td>
    </tr>
    <tr>
      <td><label for="ngo_contact_via">联系方式：</label></td>
      <td><%= h @school.ngo_contact_via %></td>
    </tr>
    <% end %>
    <tr>
      <td width="120"><label for="advice">建议和备注：</label></td>
      <td><%= simple_format @school.advice %></td>
    </tr>  
  </table>
</div>
<div id="traffic-form" style="display:none">
  <table border="0" cellspacing="5" cellpadding="0">
    <tr>
      <td><label for="traffic_sights">附近景点：</label></td>
      <td><%= h @school.traffic_sights %></td>
    </tr>
    <tr>
      <td><label for="traffic_type">交通方式：</label></td>
      <td><%= h @school.traffic_type %></td>
    </tr>
    <tr>
      <td><label for="traffic_duration">路程时间：</label></td>
      <td><%= h @school.traffic_duration %> 小时</td>
    </tr>
    <tr>
      <td class="label"><label for="traffic_description">路程攻略：</label></td>
      <td><%= simple_format @school.traffic_description %></td>
    </tr>
    <tr>
      <td><label for="traffic_charge">交通费用：</label></td>
      <td><%= h @school.traffic_charge %> 元</td>
    </tr>
  </table>
</div>
<div id="require-form" style="display:none">
  <table border="0" cellspacing="5" cellpadding="0">
    <tr>
      <td><label for="urgency_need" style="color:red">紧急需求：</label></td>
      <td><%= h @school.urgency_need %></td>
    </tr>
    <tr>
      <td><label for="books_need">书籍类：</label></td>
      <td><%= h @school.books_need %></td>
    </tr>
    <tr>
      <td><label for="stationaries_need">文具类：</label></td>
      <td><%= h @school.stationaries_need %></td>
    </tr>
    <tr>
      <td><label for="sports_need">文体类：</label></td>
      <td><%= h @school.sports_need %></td>
    </tr>
    <tr>
      <td><label for="clothes_need">衣服类：</label></td>
      <td><%= h @school.clothes_need %></td>
    </tr>
    <tr>
      <td><label for="accessories_need">教具类：</label></td>
      <td><%= h @school.accessories_need %></td>
    </tr>
    <tr>
      <td><label for="classes_need">学校活动需求：</label></td>
      <td><%= h @school.classes_need %></td>
    </tr>
    <tr>
      <td><label for="teachers_need">支教老师：</label></td>
      <td><%= h @school.teachers_need %></td>
    </tr>
    <tr>
      <td><label for="others_need">其它类：</label></td>
      <td><%= h @school.others_need %></td>
    </tr>
  </table>
</div>
<div id="finder-form" style="display:none">
  <table border="0" cellspacing="5" cellpadding="0">
		<% if logged_in? %>
    <tr>
      <td><label for="finder_name">收集人姓名：</label></td>
      <td><%= h @school.finder_name %></td>
    </tr>
    <tr>
      <td><label for="finder_email">Email：</label></td>
      <td><%= h @school.finder_email %></td>
    </tr>
    <tr>
      <td><label for="finder_qq">QQ：</label></td>
      <td><%= h @school.finder_qq %></td>
    </tr>
    <tr>
      <td><label for="finder_msn">MSN：</label></td>
      <td><%= h @school.finder_msn %></td>
    </tr>
		<% else %>
		<tr>
			<td colspan="2" align="center">详细收集人信息请<%= link_to "登录", login_url %>后浏览</td>
		</tr>
		<% end %>
    <tr>
      <td><label for="finder_survey_at">调查时间：</label></td>
      <td><%= h @school.finder_survey_at %></td>
    </tr>
  </table>
</div>

<% end -%>

<% unless @students.blank? -%>
<h3 class="nt">该校学生 <%= title_suffix %></h3>
<table border="0" cellspacing="0" cellpadding="2" class="left ol" width="100%">
  <tr>
    <th>名字</th>
    <th>性别</th>
    <th>出生年份</th>
    <th>入学年份</th>
  </tr>
  <% @students.each do |stu| -%>
  <tr>
    <td><%= link_to stu.full_name, student_url(@school.id, stu.id) %></td>
    <td><%= stu.gender_for_human %></td>
    <td><%= stu.birth.year %></td>
    <td><%= stu.enter_school_year %></td>
  </tr>
  <% end -%>  
</table>
<% end -%>


<h3 class="nt">最近的学校照片 <%= title_suffix %></h3>
<% @photos.each do |photo| -%>
  <%= link_to image_tag(photo.public_filename(:small), :style => "border: 1px solid #666;padding:2px"), photo_url(photo) %>
<% end -%>


<h3 class="nt">最近的学校留言 <%= title_suffix %></h3>
<div>
	<% if @comments.blank? -%>
  	<p>还没人留言</p>
	<% end -%>

	<% @comments.each do |comment| -%>
	<div class="span-2">
		<%= avatar_for comment.user, "large" %><br />
	</div>
	<div class="span-13 last">		
		<div class="span-11 comment_label">
			<%= link_to comment.user.login, user_path(comment.user) %>
  		写于：<span class="tip"><%= show_date comment.created_at %></span>
  		<span style="color:red"><%= "有学校信息更新" if comment.include_update? %></span>
		</div>
		<div class="span-2 last">
			<% if comment.editable_by?(current_user) -%>
			<span class="comment_label">
				<%= link_to "修改", school_edit_comment_path(@school.id, comment) %>
				<%= link_to "删除", school_comment_path(@school.id, comment), :method => 'delete', :confirm => "您确定要删除么？" %>
			</span>
			<% end -%>
		</div>
		<div class="span-13"><%= comment.content_html %></div>
	</div>
	<% end -%>
</div>
<div class="clear"></div>
<% if logged_in? -%>
	<h3 class="nt">发布新留言 <%= title_suffix %></h3>
  <% form_for :comment, :url => school_comments_path(:school_id => @school.id) do |f| -%>
    <%= render :partial => 'school_comments/form', :object => f, :locals => {:title => "Re:#{@school.title}"} %>
    <p><%= submit_tag "发布留言" %></p>
  <% end -%>
<% else -%>
  <%= link_to "登录", login_url %>后你也可以发表评论或留言
<% end -%>

<script type="text/javascript">
function show_form (id) {
  $('#base-form,#traffic-form,#require-form,#finder-form').hide();
  $('#base-li,#traffic-li,#require-li,#finder-li').removeClass("current");
  $("#" + id + "-form").show();
  $("#" + id + "-li").addClass("current");
}
</script>